load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_setting")

filegroup(
    name = "all_rules",
    srcs = [
        "//go/private/actions:all_rules",
        "//go/private/rules:all_rules",
        "//go/private/skylib/lib:all_rules",
        "//go/private/tools:all_rules",
    ] + glob(["**/*.bzl"]),
    visibility = ["//visibility:public"],
)

filegroup(
    name = "all_files",
    testonly = True,
    srcs = [
        "//go/private/actions:all_files",
        "//go/private/rules:all_files",
        "//go/private/skylib/lib:all_files",
        "//go/private/tools:all_files",
    ] + glob(["**"]),
    visibility = ["//visibility:public"],
)

config_setting(
    name = "stamp",
    values = {"stamp": "true"},
    visibility = ["//:__pkg__"],
)

config_setting(
    name = "is_strip_always",
    values = {"strip": "always"},
    visibility = ["//:__pkg__"],
)

config_setting(
    name = "is_strip_sometimes_fastbuild",
    values = {
        "strip": "sometimes",
        "compilation_mode": "fastbuild",
    },
    visibility = ["//:__pkg__"],
)

bzl_library(
    name = "context",
    srcs = ["context.bzl"],
    visibility = [
        "//docs:__subpackages__",
        "//extras:__pkg__",  # Manually added
        "//go:__subpackages__",
    ],
    deps = [
        ":common",
        ":mode",
        ":providers",
        "//go/platform:apple",
        "//go/private:go_toolchain",
        "//go/private/rules:transition",
        "@bazel_skylib//lib:paths",
        "@bazel_skylib//rules:common_settings",
        "@bazel_tools//tools/build_defs/cc:action_names.bzl",
        "@bazel_tools//tools/cpp:toolchain_utils.bzl",
        "@io_bazel_rules_go_bazel_features//:features",
        "@io_bazel_rules_nogo//:scope.bzl",
    ],
)

bzl_library(
    name = "go_toolchain",
    srcs = ["go_toolchain.bzl"],
    visibility = [
        "//extras:__pkg__",  # Manually added
        "//go:__subpackages__",
    ],
    deps = [
        "//go/private:platforms",
        "//go/private:providers",
        "//go/private/actions:archive",
        "//go/private/actions:binary",
        "//go/private/actions:link",
        "//go/private/actions:stdlib",
        "@bazel_skylib//lib:selects",
    ],
)

bzl_library(
    name = "repositories",
    srcs = [
        "polyfill_bazel_features.bzl",
        "repositories.bzl",
    ],
    visibility = ["//go:__subpackages__"],
    # Don't list dependency on @bazel_tools//tools/build_defs/repo:http.bzl
    deps = [
        ":common",
        ":nogo",
        "//go/private/skylib/lib:versions",
        "//proto:gogo",
    ],  # keep
)

bzl_library(
    name = "sdk",
    srcs = ["sdk.bzl"],
    visibility = ["//go:__subpackages__"],
    deps = [
        "//go/private:common",
        "//go/private:nogo",
        "//go/private:platforms",
        "//go/private/skylib/lib:versions",
        "@bazel_tools//tools/build_defs/repo:utils.bzl",
    ],
)

bzl_library(
    name = "common",
    srcs = ["common.bzl"],
    visibility = ["//go:__subpackages__"],
)

bzl_library(
    name = "mode",
    srcs = ["mode.bzl"],
    visibility = ["//go:__subpackages__"],
)

bzl_library(
    name = "nogo",
    srcs = ["nogo.bzl"],
    visibility = ["//go:__subpackages__"],
)

bzl_library(
    name = "platforms",
    srcs = ["platforms.bzl"],
    visibility = ["//go:__subpackages__"],
)

bzl_library(
    name = "providers",
    srcs = ["providers.bzl"],
    visibility = [
        "//extras:__pkg__",
        "//go:__subpackages__",
        "//proto:__pkg__",  # keep
    ],
)

bzl_library(
    name = "rpath",
    srcs = ["rpath.bzl"],
    visibility = [
        "//docs:__subpackages__",
        "//go:__subpackages__",
    ],
)

# Usually false. This is only true when we are building nogo itself in which
# because that rule uses an incoming transition to switch this to true.
bool_setting(
    name = "bootstrap_nogo",
    build_setting_default = False,
    visibility = ["//visibility:public"],
)

# Usually true. The entire toolchain gets nogo to use in builds via the
# go_context_data rule, which has an incoming transition that flips this flag
# to true. This will only be false in host mode (which disallows any
# transitions) or accessing nogo without going through go_context_data (which
# does not happen in rules_go and does not seem to be useful).
bool_setting(
    name = "request_nogo",
    build_setting_default = False,
    visibility = ["//visibility:public"],
)

# Controls whether nogo alias will reference a noop or the configured nogo.
# This *MUST* default to the noop to allow for tools to be built in the
# deprecated "host" mode. Host mode cannot perform configuration transitions
# so it cannot avoid circular dependencies. Therefore the default must work
# without performing any transitions. The tradeoff is that nogo analysis is not
# performed for any target built in host mode - this is not as bad as it seems
# as most tools can (and should) use "exec" configuration instead of host which
# does support transitions.
config_setting(
    name = "nogo_active",
    flag_values = {
        ":bootstrap_nogo": "False",
        ":request_nogo": "True",
    },
    visibility = ["//visibility:public"],
)

bool_setting(
    name = "always_true",
    build_setting_default = True,
    visibility = ["//visibility:public"],
)

# Only used by //:go_config.
config_setting(
    name = "is_compilation_mode_dbg",
    values = {
        "compilation_mode": "dbg",
    },
    visibility = ["//:__pkg__"],
)
